package com.qifan.energy.widget.dialog;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDialog;

import com.qifan.energy.R;
import com.wang.avi.AVLoadingIndicatorView;

public class LoadingDialog extends AppCompatDialog {

    private static LoadingDialog loadingDialog;
    private AVLoadingIndicatorView avi;

    public static LoadingDialog getInstance(Context context) {
        /*if (null == loadingDialog) {
        }*/
        loadingDialog = new LoadingDialog(context, R.style.TransparentDialog); //设置AlertDialog背景透明
        loadingDialog.setCancelable(false);
        loadingDialog.setCanceledOnTouchOutside(false);
        return loadingDialog;
    }

    public LoadingDialog(@NonNull Context context, int themeResId) {
        super(context,themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_loading);
        avi = (AVLoadingIndicatorView)this.findViewById(R.id.avi);
    }

    /*@Override
    protected void onStart() {
        super.onStart();
        this.setContentView(R.layout.dialog_loading);
        avi = this.findViewById(R.id.avi);
    }*/

    @Override
    public void show() {
        super.show();
        avi.show();
    }

    @Override
    public void dismiss() {
        if (avi != null){
            avi.hide();
        }
        super.dismiss();
    }
}
